FROM node:12-buster as buildWeb
WORKDIR /workspace
COPY webui webui

WORKDIR /workspace/webui
RUN npm install
RUN npm run build:prod

FROM python:3.7-buster

RUN echo 'deb http://archive.debian.org/debian/ stretch main contrib non-free \ 
    deb-src http://archive.debian.org/debian/ stretch main contrib non-free \ 
    deb http://archive.debian.org/debian-security/ stretch/updates main contrib non-free \ 
    deb-src http://archive.debian.org/debian-security/ stretch/updates main contrib non-free \ 
    deb http://archive.debian.org/debian/ stretch-backports main contrib non-free \ 
    ' > /etc/apt/sources.list && \
    apt-get update && \
    apt update && \
    apt install -y libtinfo5 --allow-remove-essential && \
    apt install -y ncurses-base

WORKDIR /workspace
COPY webapi webapi

WORKDIR /workspace/webapi
RUN pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple && \
    pip install -U setuptools && \
    pip install -r requirements.txt
COPY --from=buildWeb /workspace/webui/dist/static static
COPY --from=buildWeb /workspace/webui/dist/index.html static/

EXPOSE 5000

ENTRYPOINT uvicorn app:app --host 0.0.0.0 --port 5000
